import 'package:xvideos/hj_model/video_model.dart';

class SearchIndexModel {
  List<HotTag>? hotTag;
  List<RecommendList>? recommendList;

  SearchIndexModel({this.hotTag, this.recommendList});

  SearchIndexModel.fromJson(Map<String, dynamic> json) {
    if (json['hotTag'] != null) {
      hotTag = <HotTag>[];
      json['hotTag'].forEach((v) {
        hotTag!.add(HotTag.fromJson(v));
      });
    }
    if (json['recommendList'] != null) {
      recommendList = <RecommendList>[];
      json['recommendList'].forEach((v) {
        recommendList!.add(RecommendList.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (hotTag != null) {
      data['hotTag'] = hotTag!.map((v) => v.toJson()).toList();
    }
    if (recommendList != null) {
      data['recommendList'] = recommendList!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class HotTag {
  String? id;
  String? name;
  int? type;
  int? hot;

  HotTag({this.id, this.name, this.type, this.hot});

  HotTag.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    type = json['type'];
    hot = json['hot'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['type'] = type;
    return data;
  }
}

class RecommendList {
  List<Contents>? contents;
  int? countBrowse;
  int? countCollect;
  int? countComment;
  int? countDisLike;
  int? countLike;
  int? countPurchases;
  int? countView;
  String? createdAt;
  int? direction;
  int? freeTime;
  bool? hasFollow;
  String? horizontalCover;
  String? id;
  int? kind;
  String? mId;
  VidStatus? mediaStatus;
  String? mediaType;
  String? moduleName;
  int? number;
  int? permission;
  bool? permissionIconHide;
  int? price;
  String? sId;
  String? sectionName;
  int? sectionSort;
  int? sellType;
  int? sortCode;
  int? status;
  String? summary;
  List<HotTag>? tagDetails;
  List<String>? tags;
  String? title;
  int? totalEpisode;
  int? updateStatus;
  String? updateTime;
  String? verticalCover;

  RecommendList(
      {this.contents,
      this.countBrowse,
      this.countCollect,
      this.countComment,
      this.countDisLike,
      this.countLike,
      this.countPurchases,
      this.countView,
      this.createdAt,
      this.direction,
      this.freeTime,
      this.hasFollow,
      this.horizontalCover,
      this.id,
      this.kind,
      this.mId,
      this.mediaStatus,
      this.mediaType,
      this.moduleName,
      this.number,
      this.permission,
      this.permissionIconHide,
      this.price,
      this.sId,
      this.sectionName,
      this.sectionSort,
      this.sellType,
      this.sortCode,
      this.status,
      this.summary,
      this.tagDetails,
      this.tags,
      this.title,
      this.totalEpisode,
      this.updateStatus,
      this.updateTime,
      this.verticalCover});

  String? get coverH {
    return (horizontalCover?.isNotEmpty == true) ? horizontalCover : verticalCover;
  }

  String? get coverV {
    return (verticalCover?.isNotEmpty == true) ? verticalCover : horizontalCover;
  }

  String getUpdateString() {
    String unit = '集';
    if (mediaType == 'image') {
      unit = '话';
    }
    if (updateStatus == 1) {
      return '更新$totalEpisode$unit';
    } else if (updateStatus == 2 || updateStatus == 0) {
      return '已完结';
    } else {
      return '';
    }
  }

  RecommendList.fromJson(Map<String, dynamic> json) {
    if (json['contents'] != null) {
      contents = <Contents>[];
      json['contents'].forEach((v) {
        contents!.add(Contents.fromJson(v));
      });
    }
    countBrowse = json['countBrowse'];
    countCollect = json['countCollect'];
    countComment = json['countComment'];
    countDisLike = json['countDisLike'];
    countLike = json['countLike'];
    countPurchases = json['countPurchases'];
    countView = json['countView'];
    createdAt = json['createdAt'];
    direction = json['direction'];
    freeTime = json['freeTime'];
    hasFollow = json['hasFollow'];
    horizontalCover = json['horizontalCover'];
    id = json['id'];
    kind = json['kind'];
    mId = json['mId'];
    mediaStatus = json['mediaStatus'] != null ? VidStatus.fromMap(json['mediaStatus']) : null;
    mediaType = json['mediaType'];
    moduleName = json['moduleName'];
    number = json['number'];
    permission = json['permission'];
    permissionIconHide = json['permissionIconHide'];
    price = json['price'];
    sId = json['sId'];
    sectionName = json['sectionName'];
    sectionSort = json['sectionSort'];
    sellType = json['sellType'];
    sortCode = json['sortCode'];
    status = json['status'];
    summary = json['summary'];
    if (json['tagDetails'] != null) {
      tagDetails = <HotTag>[];
      json['tagDetails'].forEach((v) {
        tagDetails!.add(HotTag.fromJson(v));
      });
    }
    tags = json['tags'] != null ? json['tags'].cast<String>() : [];
    title = json['title'];
    totalEpisode = json['totalEpisode'];
    updateStatus = json['updateStatus'];
    updateTime = json['updateTime'];
    verticalCover = json['verticalCover'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (contents != null) {
      data['contents'] = contents!.map((v) => v.toJson()).toList();
    }
    data['countBrowse'] = countBrowse;
    data['countCollect'] = countCollect;
    data['countComment'] = countComment;
    data['countDisLike'] = countDisLike;
    data['countLike'] = countLike;
    data['countPurchases'] = countPurchases;
    data['countView'] = countView;
    data['createdAt'] = createdAt;
    data['direction'] = direction;
    data['freeTime'] = freeTime;
    data['hasFollow'] = hasFollow;
    data['horizontalCover'] = horizontalCover;
    data['id'] = id;
    data['kind'] = kind;
    data['mId'] = mId;
    if (mediaStatus != null) {
      data['mediaStatus'] = mediaStatus!.toJson();
    }
    data['mediaType'] = mediaType;
    data['moduleName'] = moduleName;
    data['number'] = number;
    data['permission'] = permission;
    data['permissionIconHide'] = permissionIconHide;
    data['price'] = price;
    data['sId'] = sId;
    data['sectionName'] = sectionName;
    data['sectionSort'] = sectionSort;
    data['sellType'] = sellType;
    data['sortCode'] = sortCode;
    data['status'] = status;
    data['summary'] = summary;
    if (tagDetails != null) {
      data['tagDetails'] = tagDetails!.map((v) => v.toJson()).toList();
    }
    data['tags'] = tags;
    data['title'] = title;
    data['totalEpisode'] = totalEpisode;
    data['updateStatus'] = updateStatus;
    data['updateTime'] = updateTime;
    data['verticalCover'] = verticalCover;
    return data;
  }
}

class Contents {
  String? audioUrl;
  int? countBrowse;
  int? countCollect;
  int? countComment;
  int? countDisLike;
  int? countLike;
  int? countPurchases;
  String? createdAt;
  int? episodeNumber;
  int? height;
  String? id;
  int? listenPermission;
  String? md5;
  String? mediaId;
  int? mediaSize;
  VidStatus? mediaStatus;
  String? name;
  int? playTime;
  int? price;
  int? ratio;
  String? text;
  String? updateTime;
  List<String>? urlSet;
  String? videoUrl;
  int? weight;

  Contents(
      {this.audioUrl,
      this.countBrowse,
      this.countCollect,
      this.countComment,
      this.countDisLike,
      this.countLike,
      this.countPurchases,
      this.createdAt,
      this.episodeNumber,
      this.height,
      this.id,
      this.listenPermission,
      this.md5,
      this.mediaId,
      this.mediaSize,
      this.mediaStatus,
      this.name,
      this.playTime,
      this.price,
      this.ratio,
      this.text,
      this.updateTime,
      this.urlSet,
      this.videoUrl,
      this.weight});

  Contents.fromJson(Map<String, dynamic> json) {
    audioUrl = json['audioUrl'];
    countBrowse = json['countBrowse'];
    countCollect = json['countCollect'];
    countComment = json['countComment'];
    countDisLike = json['countDisLike'];
    countLike = json['countLike'];
    countPurchases = json['countPurchases'];
    createdAt = json['createdAt'];
    episodeNumber = json['episodeNumber'];
    height = json['height'];
    id = json['id'];
    listenPermission = json['listenPermission'];
    md5 = json['md5'];
    mediaId = json['mediaId'];
    mediaSize = json['mediaSize'];
    mediaStatus = json['mediaStatus'] != null ? VidStatus.fromMap(json['mediaStatus']) : null;
    name = json['name'];
    playTime = json['playTime'];
    price = json['price'];
    ratio = json['ratio'];
    text = json['text'];
    updateTime = json['updateTime'];
    urlSet = json['urlSet'] != null ? json['urlSet'].cast<String>() : [];
    videoUrl = json['videoUrl'];
    weight = json['weight'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['audioUrl'] = audioUrl;
    data['countBrowse'] = countBrowse;
    data['countCollect'] = countCollect;
    data['countComment'] = countComment;
    data['countDisLike'] = countDisLike;
    data['countLike'] = countLike;
    data['countPurchases'] = countPurchases;
    data['createdAt'] = createdAt;
    data['episodeNumber'] = episodeNumber;
    data['height'] = height;
    data['id'] = id;
    data['listenPermission'] = listenPermission;
    data['md5'] = md5;
    data['mediaId'] = mediaId;
    data['mediaSize'] = mediaSize;
    if (mediaStatus != null) {
      data['mediaStatus'] = mediaStatus!.toJson();
    }
    data['name'] = name;
    data['playTime'] = playTime;
    data['price'] = price;
    data['ratio'] = ratio;
    data['text'] = text;
    data['updateTime'] = updateTime;
    data['urlSet'] = urlSet;
    data['videoUrl'] = videoUrl;
    data['weight'] = weight;
    return data;
  }
}
